<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <th:block th:include="include :: header('工作安排列表')" />
</head>

<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>工作标题：</label>
                                <input type="text" name="arrangeTitle" />
                            </li>
                            <li>
                                <label>填报表单：</label>
                                <select name="templateId">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${templates}" th:text="${dict.templateName}"
                                        th:value="${dict.templateId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>工作状态：</label>
                                <select name="status" th:with="type=${@dict.getType('work_arrange_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="work:arrange:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                    shiro:hasPermission="work:arrange:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                    shiro:hasPermission="work:arrange:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info single disabled" onclick="progress()">
                    <i class="fa fa-edit"></i> 已上报
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('work:arrange:edit') }]];
        var removeFlag = [[${@permission.hasPermi('work:arrange:remove') }]];
        var statusDatas = [[${@dict.getType('work_arrange_status') }]];
        var prefix = ctx + "work/arrange";

        $(function () {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "工作安排",
                sortName: "updateTime",
                sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'arrangeId',
                    title: '工作安排ID',
                    visible: false
                },
                {
                    field: 'arrangeTitle',
                    title: '工作标题'
                },
                {
                    field: 'templateName',
                    title: '填报表单'
                },
                {
                    field: 'total',
                    title: '参与人数',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" onclick="allprogress(\'' + row.arrangeId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'unfillTotal',
                    title: '未上报人数',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" onclick="unprogress(\'' + row.arrangeId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'startDate',
                    title: '开始日期'
                },
                {
                    field: 'endDate',
                    title: '结束日期'
                },
                {
                    field: 'userName',
                    title: '发起人',
                    visible: false
                },
                {
                    field: 'status',
                    title: '工作状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if ("1" == row.status) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="release(\'' + row.arrangeId + '\')"><i class="fa fa-edit"></i>发布</a> ');
                        }
                        if ("2" == row.status) {
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="withdraw(\'' + row.arrangeId + '\')"><i class="fa fa-remove"></i>撤回</a> ');
                        }
                        if (!("7" == row.templateId || "8"==row.templateId || "9"==row.templateId)){
                            actions.push('<a class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="gather(\'' + row.arrangeId + '\')"><i class="fa fa-anchor"></i>汇总</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function release(arrangeId) {
            var url = prefix + "/release";
            $.modal.confirm("确认要发布吗？发布将创建新的工作进度！", function () {
                updateStatus(url, arrangeId);
            })
        }

        function withdraw(arrangeId) {
            var url = prefix + "/withdraw";
            $.modal.confirm("确认要撤回吗？撤回将删除已填报记录！", function () {
                updateStatus(url, arrangeId);
            })
        }

        function gather(arrangeId) {
            var url = prefix + "/gather/" + arrangeId
            var options = {
                title: "汇总查看",
                url: url,
                full: true,
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function updateStatus(url, arrangeId) {
            $.ajax({
                cache: true,
                type: "POST",
                url: url,
                data: {
                    "arrangeId": arrangeId,
                },
                async: false,
                error: function (request) {
                    $.modal.alertError("系统错误");
                },
                success: function (data) {
                    $.operate.successCallback(data);
                }
            });
        }

        function allprogress(arrangeId) {
            var url = prefix + '/allprogress/' + arrangeId;
            $.modal.openTab("所有工作进度", url);
        }

        function progress() {
            var url = prefix + '/progress/' + $.table.selectColumns("arrangeId");
            $.modal.openTab("已上报", url);
        }

        function unprogress(arrangeId) {
            var url = prefix + '/unprogress/' + arrangeId;
            $.modal.openTab("未上报", url);
        }
    </script>
</body>

</html>